#ifndef SCENE_MAIN_H
#define SCENE_MAIN_H

#include "Scene.h"
#include "Object.h"
#include <list>
#include <random>
#include <map>
#include <SDL_mixer.h>
#include <SDL_ttf.h>

class Game;

class SceneMain : public Scene {
public:
    ~SceneMain();

    void init() override;
    void clean() override;
    void update(float deltaTime) override;
    void render() override;
    void handleEvent(SDL_Event* event) override;

    void keyboardControl(float deltaTime);
    
    void spawnEnemy();

    void shootPlayer(void);
    void shootEnemy(Enemy* enemy);

    void updatePlayer(float deltaTime);
    void updateEnemies(float deltaTime);
    void updatePlayerProjectiles(float deltaTime);
    void updateEnemyProjectiles(float deltaTime);
    void updateExplosion(float deltaTime);
    void updateItem(float deltaTime);

    void renderPlayerProjectiles();
    void renderEnemiyProjectiles();
    void renderEnemies();
    void renderExplosion();
    void renderItems();
    void renderUI();
    
    
    SDL_FPoint getDirection(Enemy* enemy);
    void enemyExplode(Enemy *enemy);
    void dropItem(Enemy *enemy);
    void playerGetItem(Item *item);
    void changeSceneDelayed(float deltaTime, float delay);

private:
    Player player;
    bool isDead = false;
    std::mt19937 gen;   // 随机数生成器
    std::uniform_real_distribution<float> dis;  // 随机数分布器
    Mix_Music* bgm;
    std::map<std::string, Mix_Chunk*> sounds;   // 存储音效
    SDL_Texture* uiHealth;
    TTF_Font* scoreFont;
    int score = 0;
    float timerEnd = 0.0f;


    // 创建每个物体的模板
    Enemy enemyTemplate;
    ProjectilePlayer ProjectilePlayerTemplate;
    ProjectileEnemy ProjectileEnemyTemplate;
    Explosion ExplosionTemplate;
    Item ItemLiftTemplate;

    // 创建每个物体的容器
    std::list<Enemy*> enemies;
    std::list<ProjectilePlayer*> projectilesPlayer;
    std::list<ProjectileEnemy*> projectilesEnemy;
    std::list<Explosion*> explosions;
    std::list<Item*> items;
};

#endif